package global

import (
	"github.com/gorilla/websocket"
	"github.com/jinzhu/gorm"
	"net/http"
)

var (
	DBLink   *gorm.DB
	UpGrader = websocket.Upgrader{
		CheckOrigin: func(r *http.Request) bool {
			return true
		},
	}
	OnlineUser       = make(map[string]bool)
	UserSocket       = make(map[string]*websocket.Conn)
	VerificationCode = make(map[string]string)
)

func SetupDBLink() error {
	var err error
	//记得替换MySQL密码
	DBLink, err = gorm.Open("mysql", "root:*P9?vqOzLDtw@(127.0.0.1:3306)/chatingyourselfuserdb?charset=utf8mb4")
	if err == nil {
		DBLink.SingularTable(true)
		DBLink.LogMode(true)
		return nil
	}
	return err
}
